package eval.host;

import eval.utilities.configuration.ExperimentConfiguration;

/**
 * This class represent the host properties:
 * CPU - CPU capacity.
 * MEM - memory capacity.
 * currentCpuLoad - the current CPU units which in use on the host.
 * currentMemLoad - the current MEMORY units which in use on the host.
 * hostBaseEnergyConsumption - the number of electricity units which the
 * host consume when it empty. hostPowerOnEnergyConsumption - the number of 
 * electricity units which the host consume when it turned on.
 * MinLine - this is the line, (in percentage), were if the current load is 
 * above this, the host is still effective in $, comparing to it electricity cost.
 * 
 * @author Amit Peled   <amit.kapina@gmail.com>
 * @author Igal Kaufman <igal.kaufman@gmail.com>
 */
public class HostCapacity {

	protected ExperimentConfiguration configuration = ExperimentConfiguration.getSingleton();

	private int cpu;
	private int memory;
	private int currentCpuLoad;
	private int currentMemLoad;
	private int hostBaseEnergyConsumption;
	private int hostPowerOnEnergyConsumption;
	private double MinLine;


	/**
	 * @Constructor
	 * @param cpu
	 * @param memory
	 * @param hostBaseEnergyConsumption
	 * @param hostPowerOnEnergyConsumption
	 */
	public HostCapacity(int cpu, int memory, int hostBaseEnergyConsumption,
			int hostPowerOnEnergyConsumption) {
		this.cpu = cpu;
		this.memory = memory;
		this.currentCpuLoad = 0;
		this.currentMemLoad = 0;
		this.hostBaseEnergyConsumption = hostBaseEnergyConsumption;
		this.hostPowerOnEnergyConsumption = hostPowerOnEnergyConsumption;
		this.MinLine = setMinLine();
	}


	/**
	 * @return the MIN-LINE of Host
	 */
	public double getMinLine() {
		return MinLine;
	}

	/**
	 * @return the CPU capacity
	 */
	public int getCpuCapacity() {
		return cpu;
	}

	/**
	 * @return the MEM capacity
	 */
	public int getMemCapacity() {
		return memory;
	}

	/**
	 * @return the current CPU load on host
	 */
	public int getCpuCurrentLoad(){
		return currentCpuLoad;
	}

	/**
	 * @return the current MEM load on host
	 */
	public int getMemCurrentLoad(){
		return currentMemLoad;
	}

	/**
	 * @return the cost in $ on Base Energy Consumption
	 */
	public int getHostBaseEnergyConsumption(){
		return hostBaseEnergyConsumption;
	}

	/**
	 * @return the cost in $ on power On Energy Consumption
	 */
	public int getHostPowerOnEnergyConsumption(){
		return hostPowerOnEnergyConsumption;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "CPU: " + cpu + ", MEM: " + memory;
	}

	private double setMinLine() {
		return ((this.hostBaseEnergyConsumption / 
				(configuration.incomeOnLoad - configuration.loadCost)) * 100 / this.cpu);
	}
}
